#pragma once


template< typename T>
class Singleton
{
protected:
	Singleton()	{}
	~Singleton() {}

public:
	static void NewInstance();
	static void DeleteInstance();
	static inline T& Instance() { return *ms_instance; }
	static bool Exist() { return ms_instance != 0; }

private:
	Singleton( const Singleton& );
	Singleton& operator =( const Singleton& );

private:
	static T *ms_instance;
};

template <typename T>
T* Singleton<T>::ms_instance = 0;

template <typename T>
void Singleton<T>::NewInstance()
{
	if (ms_instance)
		delete ms_instance;
	ms_instance = new T();
}

template <typename T>
void Singleton<T>::DeleteInstance()
{
	if (ms_instance != NULL)
		delete ms_instance;
	ms_instance = 0;
}
